package com.ww.springboot.boot.thread.study.executor;

import lombok.SneakyThrows;

import java.util.concurrent.*;

/**
 * 描述：线程池各种队列测试
 *
 * @author wanwei
 * @since 2021-06-26 11:48
 */
public class ArraysTest {

/*
    */
/**
     * array 必须指定阻塞队列初始容量
     *//*

    public static final Executor excetor = new ThreadPoolExecutor(2, 10, 60
            , TimeUnit.SECONDS, new ArrayBlockingQueue<>(10));
*/

    /**
     * link 默认最大容量
     */
    public static final ThreadPoolExecutor excetor2 = new ThreadPoolExecutor(10, 10, 60
            , TimeUnit.SECONDS, new LinkedBlockingDeque<>(200));

    public static void main(String[] args) {

        for(int i= 0;i<100;i++){

            excetor2.execute(thread);
        }
        //shutdown之后线程池不再接收新任务 任务跑完后 进程结束
        excetor2.shutdown();
//        System.out.println("---------1-----------");
//        for(int i= 0;i<100;i++){
//            System.out.println("---------ssss-----------");
//            excetor2.execute(thread);
//        }
//        excetor2.shutdown();
//        System.out.println("---------2-----------");
    }




    public static Thread thread = new Thread(new Runnable() {
        @SneakyThrows
        @Override
        public void run() {
            System.out.println(Thread.currentThread());
            TimeUnit.SECONDS.sleep(1);
        }
    });
}
